from asyncio import gather

import pytest
import os
from common.Yaml import Yaml
from common.Request import Request
from common.Path import project_path
import allure
filepath=project_path()
#读取common.yaml文件,headers,base_url等信息
common_yaml_file=os.path.join(filepath,"common", "common.yaml")
common_yaml_data = Yaml(common_yaml_file).read_yaml()
headers=common_yaml_data['headers']
base_url=common_yaml_data['base_url']
#读取商品草稿页yaml文件
good_yaml_file=os.path.join(filepath,"api", "goods","draft", "draft_spuList.yaml")
good_yaml_data = Yaml(good_yaml_file).read_yaml()
draft_good_test_cases=good_yaml_data['test_cases']

'''
#读取插件采集页yaml文件
gather_yaml_file=os.path.join(filepath,"api", "goods","draft", "gather.yaml")
gather_yaml_data = Yaml(gather_yaml_file).read_yaml()
base_url=gather_yaml_data['base_url']
gather_test_cases=gather_yaml_data['test_cases']
'''

#实例化域名
req=Request(base_url)

@allure.feature("商品草稿页列表页相关接口测试")

#参数化案例
@pytest.mark.parametrize("draft_good_test_case",draft_good_test_cases)
#@allure.title("{test_case['story']}")


def test_draft_spuList(draft_good_test_case):
    allure.dynamic.story(draft_good_test_case['story'])
    allure.dynamic.title(draft_good_test_case['story'])
    json_dict = draft_good_test_case['data']

    #title=test_case['story']
    response=req.send_request(method=draft_good_test_case['method'],url=base_url+draft_good_test_case['url'],json=json_dict,headers=headers).json()

    #print(f"正在执行测试: {title}")
    assert response['msg']==draft_good_test_case['msg']
'''
@pytest.mark.parametrize("gather_test_case",gather_test_cases)


def test_gather(gather_test_case):
    json_dict = gather_test_case['data']
    response = req.send_request(method=gather_test_case['method'], url=base_url + gather_test_case['url'],
                                json=json_dict, headers=headers).json()

    return response
'''
